<template>
  <form class="createGroup" @submit="formSubmit" @reset="formReset">
    <view class="uni-form-item uni-column">
      <view class="title">团体名称</view>
      <view class="item">
        <input
          placeholder-style="font-size: 14px;"
          type="text"
          name="name"
          placeholder="如四（3）班、软件2组、财务部、xx公司、xx学校等"
        />
      </view>
    </view>
    <view class="uni-form-item uni-column">
      <view class="title">标签</view>
      <view class="item">
        <input
          placeholder-style="font-size: 14px;"
          type="text"
          name="label"
          placeholder="如学校、班级、公司、部门等"
        />
      </view>
    </view>
    <view class="uni-form-item uni-column">
      <view class="title">是否开放成员注册（默认开放）</view>
      <view class="item">
        <switch :checked="true" name="is_reg" />
      </view>
    </view>
    <view class="uni-form-item uni-column">
      <view class="title">是否分开使用（是否断开本团体的上级和下级的关系，公司、学校等使用）</view>
      <view class="item">
        <switch name="is_split" />
      </view>
    </view>
    <view class="uni-btn-v">
      <button type="default" form-type="reset">重置填写</button>
      <button :loading="false" form-type="submit">提交填写</button>
    </view>
  </form>
</template>

<script>
export default {
  data() {
    return {};
  },
  created() {
    // this.click2Register();
  },
  methods: {
    formSubmit(e) {
      e.detail.value.account_id = uni.getStorageSync("uid")

      // console.log(
      //   "form发生了submit事件，携带数据为：" + JSON.stringify(e.detail.value)
      // );
	uni.showLoading({
		title:'加载中'
	})
      uniCloud.callFunction({
        name: "ha_add_group",
        // data: Object.assign(e.detail.value, { order: 1 }),
        data: Object.assign(e.detail.value, {
          // account_id: uni.getStorageSync("uid"),
          order: 1,
          parent_id: ""
        }),
        success: data => {
			uni.hideLoading();
			
          if (data.result.code === 0) {
            console.log("success!");
            uni.showToast({
              title: `创建成功！`,
              duration: 1000
            });

            setTimeout(() => {
              uni.redirectTo({
                url: `./group_detail?group_id=${data.result.data.id}`
              });
            }, 1000);
          } else {
            console.log("fail!");
            uni.showToast({
              title: `${data.result.msg || "网络异常，请稍后重试！"}`,
              duration: 1000
            });
          }
        }
      });
    },
    formReset() {}
  }
};
</script>

<style lang="less">
.uni-form-item {
  padding: 5rpx 0;
}
.createGroup__name {
  height: 50rpx;
  border: 1rpx solid #666;
}
.createGroup .item {
  padding: 5rpx 12rpx;
}
.createGroup .item input {
  padding-left: 24rpx;
  height: 80rpx;
  border: 1rpx solid rgba(102, 102, 102, 0.5);
}
.createGroup .text {
  font-size: 14px;
}
view {
  color: #666 !important;
}
</style>
